package com.wh.music.Util;

public class ResultEntity<T> {
    private Integer code;
    private String msg;
    private T data;


    public ResultEntity(ResultCode code, T data) {
      this.code = code.code();
      this.msg = code.message();
      this.data = data;
    }

    public Integer getCode() {
      return code;
    }

    public void setCode(ResultCode code) {
      this.code = code.code();
    }

    public String getMsg() {
      return msg;
    }

    public void setMsg(String msg) {
      this.msg = msg;
    }

    public T getData() {
      return data;
    }

    public void setData(T data) {
      this.data = data;
    }

    public static <E> ResultEntity<E> success() {
      return new ResultEntity<E>(ResultCode.SUCCESS, null);
    }

    public static <E> ResultEntity<E> success(E data) {
      return new ResultEntity<E>(ResultCode.SUCCESS, data);
    }

    public static <E> ResultEntity<E> failed(ResultCode resultCode) {
      return new ResultEntity<E>(resultCode, null);
    }
  public static <E> ResultEntity<E> failed(ResultCode resultCode, E data) {
    return new ResultEntity<E>(resultCode, null);
  }
}
